<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 <link href="${ctx}/js/ztree/css/demo.css" type="text/css" rel="stylesheet">
 <link href="${ctx}/js/ztree/css/zTreeStyle/zTreeStyle.css" type="text/css" rel="stylesheet">
<%@ include file="/commons/script.jsp" %>
<script type="text/javascript" src="${ctx}/js/ztree/js/jquery.ztree.core-3.3.min.js"></script>
<script src="${ctx}/js/jquery.validate.min.js" type="text/javascript"></script>
<script src="${ctx}/js/validate.addmethod.js" type="text/javascript"></script>
<script src="${ctx}/js/messages_cn.js" type="text/javascript"></script>
<script src="${ctx}/js/util.js" type="text/javascript"></script>
<title>添加用户</title>
<style type="text/css">
	.m_r_search_con table input[type="checkbox"]{width:15px;height:15px;}
	.m_r_search_con table label{padding-right: 10px; display: inline-block;width: 60px;}
	.m_r_search_con table label.error{width: auto;}
	#busiTd label{width:267px;}
</style>
</head>
<body>
  <div class="m_right">
    <div class="m_r_tips">
       <div class="m_r_lefttips">您现在的位置：<a href="${ctx}/admin/home.jsp">首页</a>&gt;系统管理&gt;账号管理&gt;新增账号</div>
       <jsp:include page="/commons/admin/admin_login_remind.jsp"/>
    </div>

    <s:form id="account_form" method="post" action="addPcAccount" namespace="/admin/account">
    <s:hidden name="acc.type" value="0"/>
    <s:hidden name="acc.createUser.aid" value="%{#session.PC_ACCOUNT.aid}"/>
    <div class="m_r_search">
       <div class="m_r_search_con">
         <table width="700" border="0" cellspacing="0" cellpadding="0" align="center"  style="border-collapse: collapse;border-spacing: 0; border:0;margin:0px auto; ">
              <col width="100"><col width="">
              <tr>
                <td class="m_r_s_con_td">&nbsp;</td>
                <td class="m_r_s_con_text">&nbsp;</td>
              </tr>
		      <tr>
                <td class="m_r_s_con_td"><span class="required_mark">*</span>所属机构</td>
                <td class="m_r_s_con_text">&nbsp;
                <input id="oname" type="text" readonly="readonly" value="" class="text_input" style="width:230px;"/>
                &nbsp;<a id="menuBtn" href="#" onclick="showMenu(); return false;">选择</a>
                <input id="oid" name="acc.organization.oid" value="" type="hidden"/>
              </tr>
			<tr>
                <td class="m_r_s_con_td"><span class="required_mark">*</span>用户编号</td>
                <td class="m_r_s_con_text">&nbsp;
                <s:textfield name="acc.numbers" id="numbers" cssClass="text_input" maxlength="50"/>
                </td>
              </tr>  
			<tr>
                <td class="m_r_s_con_td"><span class="required_mark">*</span>登录名</td>
                <td class="m_r_s_con_text">&nbsp;
                <s:textfield name="acc.username" id="username" cssClass="text_input" maxlength="30"/>
                </td>
              </tr>  
              <tr>
                <td class="m_r_s_con_td"><span class="required_mark">*</span>姓名</td>
                <td class="m_r_s_con_text">&nbsp;
                <s:textfield name="acc.realname" id="realname" cssClass="text_input" maxlength="20"/>
                </td>
              </tr> 
              <tr>
                <td class="m_r_s_con_td"><span class="required_mark">*</span>邮箱</td>
                <td class="m_r_s_con_text">&nbsp;
                <s:textfield name="acc.email" id="email" cssClass="text_input" maxlength="45"/>
                </td>
              </tr> 
              <tr>
                <td class="m_r_s_con_td"><span class="required_mark">*</span>手机</td>
                <td class="m_r_s_con_text">&nbsp;
                <s:textfield name="acc.mobile" id="mobile" cssClass="text_input" maxlength="11"/>
                </td>
              </tr> 
              <tr>
               <td class="m_r_s_con_td"><span class="required_mark">*</span>密码</td>
                <td class="m_r_s_con_text">&nbsp;
                 <input type="password" name="acc.password" id="password" class="text_input" maxlength="32"/>
                </td>
              </tr> 
              <tr>
                <td class="m_r_s_con_td"><span class="required_mark">*</span>密码确认</td>
                <td class="m_r_s_con_text">&nbsp;
                <input type="password" name="confirm_password" id="confirm_password" class="text_input" maxlength="32"/>
                </td>
              </tr>
              <tr>
                   <td class="m_r_s_con_td">职务</td>
                   <td class="m_r_s_con_text">&nbsp;
                    <s:select list="#request.dutyMap" name="acc.dutyCode" cssClass="text_input" listKey="key" listValue="value"  headerKey="" headerValue="无"/>
                   </td>
              </tr> 
              <tr>
                   <td class="m_r_s_con_td"><span class="required_mark">*</span>使用状态</td>
                   <td class="m_r_s_con_text">&nbsp;
                      <s:radio list="#{'false':'正常','true':'禁用'}" name="acc.disabled" value="false"/>
                   </td>
              </tr>
         </table>
       </div>
    </div>
    
    <div class="m_r_search_btn">
      <a href="#" class="m_r_bnt1 pad15"><s:submit name="submitBtn" value="添加" /></a>
    </div>
    
    <div id="menuContent" class="menuContent" style="display:none; position: absolute;">
        <ul id="orgTree" class="ztree" style="margin-top:0; width:200px;"></ul>
    </div>
    </s:form>
  </div>
</body>
<script type="text/javascript">
    var setting = {
        view: {
            dblClickExpand: false
        },
        data: {
            simpleData: {
                enable: true
            }
        },
        callback: {
            onClick: onClick,
            onDblClick: zTreeOnDblClick
        }
    };
    
    function onClick(e, treeId, treeNode) { 
        $("#oname").val(treeNode.name);
        $("#oid").val(treeNode.id);
        if(!treeNode.id||treeNode.id!="001"){
        	$(":checkbox[name='busiJob'][value!='1']").each(function(){
        		$(this).hide().next().hide();
        	});
        	$(":checkbox[name='busiJob']:visible").attr("checked","checked");
        }else{
        	$(":checkbox[name='busiJob']").each(function(){
        		$(this).show().next().show();
        	});
        	$(":checkbox[name='busiJob']").removeAttr("checked");
        }
    }
    
    function zTreeOnDblClick(event, treeId, treeNode) {
        hideMenu();
    }

    function showMenu() {
        var cityObj = $("#oname");
        var cityOffset = $("#oname").offset();
        $("#menuContent").css({left:cityOffset.left + "px", top:cityOffset.top + cityObj.outerHeight() + "px"}).slideDown("fast");
        $("body").bind("mousedown", onBodyDown);
    }
    
    function hideMenu() {
        $("#menuContent").fadeOut("fast");
        $("body").unbind("mousedown", onBodyDown);
    }
    function onBodyDown(event) {
        if (!(event.target.id == "menuBtn" || event.target.id == "menuContent" || $(event.target).parents("#menuContent").length>0)) {
            hideMenu();
        }
    }

	
   
	$(document).ready(function(){
		$("#oid").empty();
		  $.getJSON("${ctx}/admin/account/getOrgTreeByOid.do", function(data){
                $.fn.zTree.init($("#orgTree"), setting, data);
		  });   
	
		  $.validator.setDefaults({
			    submitHandler: function(form) { 
			        var password = $("#password")[0];
			        password.value = hex_md5(password.value); 
			        form.submit(); //不能用$("#id").submit() 会导致死循环
			    }
			});
			
		  $("#account_form").validate({
		        ignore: "",  // 开启hidden验证， 1.9版本后默认关闭
		        rules: {
		        	"acc.organization.oid":"required",
		            "acc.username": {
		            	required: true,
		            	registerName: true, //只能是英文开头 包括数字下划线
		            	remote:"${ctx}/admin/account/isValidName.do"  //传递参数为"acc.username"
		            },
		            "acc.numbers": {
		                required: true,
		                maxlength: 100
		            },
		            "acc.password": {
		                required: true,
		                minlength: 6,
		                maxlength: 32
		            },
		            "confirm_password": {
		                required: true,
		                equalTo: "#password"
		            },
		            "acc.realname": {
		                required: true,
		                maxlength:100,
		                stringCheck: true
		            },
		            "acc.email": {
		            	required: true,
		            	email:true,
		            	remote:"${ctx}/admin/account/isValidEmail.do"  //传递参数为"acc.email"
		            },
		            "acc.mobile":{
		            	required: true,
		            	isMobile:true
		            }
		        },
		      messages: {
		            "acc.organization.oid": "请选择机构",
		            "acc.realname": {
		            	required:"请输入姓名",
		            	maxlength:"姓名长度不能超过100"
		            },
		            "acc.numbers":{
		            	required: "请输入正确的用户编号"
		            },
		            "acc.username": {
		                required: "请输入合法的用户名",
		                registerName: "只能英文字母开头、可以包括数字和下划线，长度5-16之间",
		                remote:"用户名已经被占用"
		            },
		            "acc.password": {
		                required: "请输入密码",
		                minlength: "密码长度至少为6",
		                maxlength:"密码长度不能超过32"
		            },
		            "confirm_password": {
		                required: "请输入确认密码",
		                equalTo: "确认密码不一致"
		            },
		            "acc.email": {
  	            	   required: "请输入邮箱",
		               email:"请输入正确的邮箱格式",
		               remote:"该邮箱已经被占用"	
		            },
		            "acc.mobile":{
		            	required: "请输入手机号"
		            }
		        }
		    });  
		  
	});
	
	
</script>
</html>